﻿package cn.poco.service.impl;

import java.io.InputStream;
import java.util.ArrayList;

import android.util.Log;

import cn.poco.bean.Restaurant;
import cn.poco.bean.Topic;
import cn.poco.service.ITopic;
import cn.poco.util.UrlConnectionUtil;
import cn.poco.util.xmlparse.RestaurantXmlparse;
import cn.poco.util.xmlparse.TopicXmlparse;

public class TopicImpl implements ITopic {

	private final static String TAG = "TopicImpl";
	@Override
	public ArrayList<Topic> getTopics(int s, int l, String lid, String dish) throws Exception {

		InputStream inStream = null;
		StringBuffer sb = new StringBuffer();
			sb.append(BASE_TOPICS_PATH);
			if(s>=0){
				sb.append("?s=").append(s);
			}
			if(l>=0){
				sb.append("&l=").append(l);
			}
			if(lid!=null){
				sb.append("&cd=").append(lid);
			}
			if(dish!=null){
				sb.append("&dish=").append(dish);
			}
		
			Log.i(TAG, sb.toString());
			inStream = UrlConnectionUtil.getRequest(sb.toString());
			return TopicXmlparse.getXml(inStream);
	
	}
/*	@Override
	public Topic getTopic(String tid) throws Exception {
		InputStream inStream = null;
		String url = TOPICS_DETAIL_PATH.replace("#a", tid);
		inStream = UrlConnectionUtil.getRequest(url);
		return TopicXmlparse.getXml(inStream).get(0);
	}*/
	
	@Override
	public ArrayList<Restaurant> getResByTid(String tid, int s, int l)
			throws Exception {
		InputStream inStream = null;
		String path = RES_TID_PATH.replace("#a", tid)
			.replace("#b", String.valueOf(s))
			.replace("#c", String.valueOf(l));
		Log.i(TAG, path);
		inStream = UrlConnectionUtil.getRequest(path);
		return RestaurantXmlparse.getXml(inStream);
	
	}
	
	

}
